package com.youyi.yyviewsdklibrary.Dialog.core;

import android.app.Dialog;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;

import com.lkx.liandianqinew.R;
import com.youyi.yyviewsdklibrary.Dialog.XPopup;
import com.youyi.yyviewsdklibrary.Dialog.util.FuckRomUtils;
import com.youyi.yyviewsdklibrary.Dialog.util.XPopupUtils;

public class FullScreenDialog extends Dialog {
    BasePopupView contentView;

    public FullScreenDialog(Context context) {
        super(context, R.style._XPopup_TransparentDialog);
    }

    /* access modifiers changed from: protected */
    public void onCreate(Bundle bundle) {
        BasePopupView basePopupView;
        super.onCreate(bundle);
        if (getWindow() != null && (basePopupView = this.contentView) != null && basePopupView.popupInfo != null) {
            if (this.contentView.popupInfo.enableShowWhenAppBackground) {
                if (Build.VERSION.SDK_INT >= 26) {
                    getWindow().setType(2038);
                } else {
                    getWindow().setType(2003);
                }
            }
            if (this.contentView.popupInfo.keepScreenOn) {
                getWindow().addFlags(128);
            }
            getWindow().setBackgroundDrawable(null);
            boolean z = false;
            getWindow().getDecorView().setPadding(0, 0, 0, 0);
            getWindow().setFlags(16777216, 16777216);
            getWindow().setSoftInputMode(16);
            getWindow().getDecorView().setSystemUiVisibility(1280);
            if (Build.VERSION.SDK_INT == 19) {
                getWindow().clearFlags(67108864);
            } else if (Build.VERSION.SDK_INT == 20) {
                setWindowFlag(201326592, true);
            } else if (Build.VERSION.SDK_INT >= 21) {
                setWindowFlag(201326592, false);
                getWindow().setStatusBarColor(0);
                int navigationBarColor = getNavigationBarColor();
                if (navigationBarColor != 0) {
                    getWindow().setNavigationBarColor(navigationBarColor);
                }
                getWindow().addFlags(Integer.MIN_VALUE);
            }
            if (!this.contentView.popupInfo.hasNavigationBar.booleanValue()) {
                hideNavigationBar();
            }
            if (!this.contentView.popupInfo.isRequestFocus) {
                getWindow().setFlags(8, 8);
            }
            setStatusBarLightMode();
            setNavBarLightMode();
            getWindow().setLayout(-1, -1);
            if (getContext().getResources().getConfiguration().orientation == 1) {
                z = true;
            }
            if (isFuckVIVORoom() && z) {
                getWindow().setLayout(XPopupUtils.getAppWidth(getContext()), Math.max(XPopupUtils.getAppHeight(getContext()), XPopupUtils.getScreenHeight(getContext())));
                getWindow().getDecorView().setTranslationY((float) (-XPopupUtils.getStatusBarHeight()));
            }
            setContentView(this.contentView);
        }
    }

    private int getNavigationBarColor() {
        if (this.contentView.popupInfo.navigationBarColor == 0) {
            return XPopup.getNavigationBarColor();
        }
        return this.contentView.popupInfo.navigationBarColor;
    }

    public boolean isFuckVIVORoom() {
        boolean z = Build.MODEL.contains("Y") || Build.MODEL.contains("y") || Build.MODEL.contains("V1809A");
        if (!FuckRomUtils.isVivo()) {
            return false;
        }
        if ((Build.VERSION.SDK_INT == 26 || Build.VERSION.SDK_INT == 27) && z) {
            return true;
        }
        return false;
    }

    public void setWindowFlag(int i, boolean z) {
        WindowManager.LayoutParams attributes = getWindow().getAttributes();
        if (z) {
            attributes.flags = i | attributes.flags;
        } else {
            attributes.flags = (~i) & attributes.flags;
        }
        getWindow().setAttributes(attributes);
    }

    private void setStatusBarLightMode() {
        if (!this.contentView.popupInfo.hasStatusBar.booleanValue()) {
            getWindow().getDecorView().setSystemUiVisibility(((ViewGroup) getWindow().getDecorView()).getSystemUiVisibility() | 1284);
            return;
        }
        int i = this.contentView.popupInfo.isLightStatusBar == 0 ? XPopup.isLightStatusBar : this.contentView.popupInfo.isLightStatusBar;
        if (Build.VERSION.SDK_INT >= 23 && i != 0) {
            View decorView = getWindow().getDecorView();
            int systemUiVisibility = decorView.getSystemUiVisibility();
            decorView.setSystemUiVisibility(i > 0 ? systemUiVisibility | 8192 : systemUiVisibility & -8193);
            getWindow().setStatusBarColor(this.contentView.popupInfo.statusBarBgColor);
        }
    }

    public void hideNavigationBar() {
        ViewGroup viewGroup = (ViewGroup) getWindow().getDecorView();
        int childCount = viewGroup.getChildCount();
        for (int i = 0; i < childCount; i++) {
            View childAt = viewGroup.getChildAt(i);
            int id = childAt.getId();
            if (id != -1 && "navigationBarBackground".equals(getResNameById(id))) {
                childAt.setVisibility(View.INVISIBLE);
            }
        }
        viewGroup.setSystemUiVisibility(viewGroup.getSystemUiVisibility() | 4610);
    }

    private String getResNameById(int i) {
        try {
            return getContext().getResources().getResourceEntryName(i);
        } catch (Exception unused) {
            return "";
        }
    }

    public void setNavBarLightMode() {
        int i = this.contentView.popupInfo.isLightNavigationBar == 0 ? XPopup.isLightNavigationBar : this.contentView.popupInfo.isLightNavigationBar;
        if (Build.VERSION.SDK_INT >= 26 && i != 0) {
            View decorView = getWindow().getDecorView();
            int systemUiVisibility = decorView.getSystemUiVisibility();
            decorView.setSystemUiVisibility(i > 0 ? systemUiVisibility | 16 : systemUiVisibility & -17);
        }
    }

    public FullScreenDialog setContent(BasePopupView basePopupView) {
        if (basePopupView.getParent() != null) {
            ((ViewGroup) basePopupView.getParent()).removeView(basePopupView);
        }
        this.contentView = basePopupView;
        return this;
    }

    public boolean dispatchTouchEvent(MotionEvent motionEvent) {
        if (isFuckVIVORoom()) {
            motionEvent.setLocation(motionEvent.getX(), motionEvent.getY() + ((float) XPopupUtils.getStatusBarHeight()));
        }
        return super.dispatchTouchEvent(motionEvent);
    }
}
